package com.own.core.html.component;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.wicket.Component;
import org.apache.wicket.resource.loader.IStringResourceLoader;

import com.own.core.object.lookup.message.Message;
import com.own.core.operation.DbOperation;

public class OwnResourceLoader implements IStringResourceLoader {

	@Override
	public String loadStringResource(Class<?> clazz, String key, Locale locale,
			String style, String variation) {
	
		return loadStringResource( (Component)null,  key,
				locale ,  style,  variation);
	}

	@Override
	public String loadStringResource(Component component, String key,
			Locale locale, String style, String variation) {
		
		Map paraMap = new HashMap();
		paraMap.put("key", key );
//		paraMap.put("language", key );
		 
		
		List message= DbOperation.getME()
				.executeNamedQuery("message.loadByKey",paraMap);
		
	if(message== null || message.isEmpty()){
		
		return null;
	}
	
		return ((Message)message.get(0)).getValue();
	}

}
